<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
	ul{
		margin-left:25;padding:0;
 		list-style:none; 
	}
	.mini-checkboxlist-item{
		padding: 10px;
	}
</style>
</head>
<body>
	<div id="datagrid1" class="mini-datagrid" showPager="false" onlyCheckSelection="true" idField="id" allowCellWrap="true" url="customer_sms_view.do" style="width:100%;height:auto;">
		<div property="columns">
			<div type="indexcolumn" width="15"></div>
			<div field="sendSeatName" width="50" headerAlign="center" align="center">发送座席</div>
			<div field="content" width="250" headerAlign="center" align="left">内容</div>
			<div field="statusVal" width="50" headerAlign="center" align="center">发送状态</div>
			<div field="createTime" width="70" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">时间</div>
		</div>
	</div>
	<fieldset style="border:solid 1px #aaa;padding:3px;">
		<legend >添加短信</legend>
		<input id="customer_id" class="mini-hidden" />
		<div id="form1">
	        <table style="width: 100%">
	        	<tr>
	        		<td>短信模版类型：</td>
	        		<td><input class="mini-combobox" url="dictionary_cm_key_val_view.do?typeName=SMS_PHRASE_TYPE"
            		 	allowInput="false" style="width:150px;" textField="keyValue" valueField="keyName" onvaluechanged="onChanged"/></td>
            		<td>短信模版：</td>
            		<td><input class="mini-combobox" id="smsTemple" allowInput="false" style="width:500px;" textField="content" valueField="id" onvaluechanged="onTempleChanged"/></td>
	        	</tr>
		        <tr>
		        	<td>客户手机号：</td>
		        	<td>
		        		<input name="phoneNum" id="phone_num" style="width: 150px;" valueField="phoneNum" textField="phoneNum" class="mini-combobox"
			        		 url="" required="true"/>
		        	</td>
		        	<td>内容：</td>
		        	<td>
		        		<input class="mini-textbox" id="smsContent" name="content" style="width: 500px;" required="true"/>
		        	</td>
		        	<td>
		        		<sec:authorize url='/sms_save.do'>
		        		<a class="mini-button" onclick="onOk" style="width:50px;">添加</a>
		        		</sec:authorize>
		        	</td>
		        </tr>
	    	</table>
		</div>
	</fieldset>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	var form1 = new mini.Form("form1");
	var cId = mini.get("customer_id");
	var phoneNum = mini.get("phone_num");
	function SetData(data) {
		data = mini.clone(data);
		cId.setValue(data.customerId);
		grid.load({customerId: data.customerId});
		var url = "customer_tel_find.do?customerId=" + data.customerId;
		phoneNum.load(url);
	}
	
	function onOk(){
		var o = form1.getData(true); 
	    form1.validate();
	    if (form1.isValid() == false) return;
	    $.ajax({
	        url: "sms_save.do?customerId=" + cId.getValue(),
			type: 'post',
			dataType: 'json',
	        data: o,
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	form1.reset();
	            	grid.load({customerId: cId.getValue()});
	            }else{
	            	mini.alert("数据错误！");
	            }
	        }
	    });
	}
	
	function onChanged(e) {
		var newUrl = "sms_phrase_by_type.do?type="+e.value;
		var st = mini.get("smsTemple");
		st.load(newUrl);
	}

	function onTempleChanged(e){
		var sms = mini.get("smsContent");
		sms.setValue(e.selected.content);
	}
</script>
</body>
</html>